using UnityEngine;

public class MissionTargetTimer : MissionTargetBase
{
	public bool useTimer;

	public bool timerIsStarted;

	public float timeForComplete = 100000f;

	public float remainingTime = 10f;

	private float oldRemainingTime = 10f;

	private void Update()
	{
		if (useTimer && timerIsStarted)
		{
			remainingTime -= Time.deltaTime;
			if (remainingTime <= 0f)
			{
				remainingTime = 0f;
				timerIsStarted = false;
				OnTimeOut();
			}
			else if ((int)oldRemainingTime != (int)remainingTime)
			{
				OnUpdateTimer();
			}
			oldRemainingTime = remainingTime;
		}
	}

	public void StartTimer(bool reset = false)
	{
		if (reset)
		{
			remainingTime = timeForComplete;
		}
		timerIsStarted = true;
		OnTimeStart();
	}

	public void PauseTimer()
	{
		timerIsStarted = false;
	}

	public void ResetTimer()
	{
		timerIsStarted = false;
		remainingTime = timeForComplete;
	}

	protected virtual void OnTimeStart()
	{
	}

	protected virtual void OnTimeOut()
	{
	}

	protected virtual void OnUpdateTimer()
	{
	}
}
